import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 模具储位信息 */
export interface Storage {
  id: number // 储位id
  status?: number // 启用状态
  warehouseId?: number // 仓库id
  code: string // 编码
  name?: string // 名称
  number?: number // 数量
  description: string // 备注
}

// 模具储位 API
export const StorageApi = {
  getStorageAll: async () => {
    return await request.get({ url: `/mold/storage/all` })
  },

  getListOfWarehouse: async (warehouseId: number) => {
    return await request.get({ url: `/mold/storage/list-of-warehouse?warehouse_id=${warehouseId}` })
  },

  // 查询模具储位分页
  getStoragePage: async (params: any) => {
    return await request.get({ url: `/mold/storage/page`, params })
  },

  // 查询模具储位详情
  getStorage: async (id: number) => {
    return await request.get({ url: `/mold/storage/get?id=` + id })
  },

  // 新增模具储位
  createStorage: async (data: Storage) => {
    return await request.post({ url: `/mold/storage/create`, data })
  },

  // 修改模具储位
  updateStorage: async (data: Storage) => {
    return await request.put({ url: `/mold/storage/update`, data })
  },

  // 删除模具储位
  deleteStorage: async (id: number) => {
    return await request.delete({ url: `/mold/storage/delete?id=` + id })
  },

  /** 批量删除模具储位 */
  deleteStorageList: async (ids: number[]) => {
    return await request.delete({ url: `/mold/storage/delete-list?ids=${ids.join(',')}` })
  },

  // 导出模具储位 Excel
  exportStorage: async (params) => {
    return await request.download({ url: `/mold/storage/export-excel`, params })
  },

  // 下载导入模板
  importTemplate: async () => {
    return request.download({ url: '/mold/storage/get-import-template' })
  }
}
